Fix Resume() to fully reinitialize USB device after suspend#249
Conversation
Replace the broken Resume() with a retry loop that does a full init.open() (USB re-enumeration + sensor init), giving the kernel time to enumerate the USB device after wake. - Call init.open() instead of init.open_common() for fresh USB handle - Retry up to 20 times with 100ms delay (2s max) for USB enumeration - Catch Exception since usb.open() raises plain Exception when device is not yet enumerated
|
I tested this on my T480, it seems to fix issues related, good job |
Test report: suspend/resume fix works on ThinkPad T480 (
|
Replace the broken
Resume()implementation with a proper retry loop that does a fullinit.open()(USB re-enumeration + sensor init), giving the kernel time to enumerate the USB device after wake.Motivation
The existing
Resume()calledinit.open_common()which skipsusb.open()— it assumes the USB handle is still valid. After suspend, the kernel resets the USB bus and the handle goes stale, causingUSBError: [Errno 19] No such device. The original single bare-except retry was also insufficient since the USB device may not be enumerated yet whenResume()is called.This became visible after open-fprintd PR #24 added
PrepareForSleephandling, which now callsDevice.Resume()automatically on wake. The hyprlock maintainer rightly pointed out that DBus services should handle suspend internally and stay alive across sleep cycles.Related issues
This change, together with open-fprintd PR #24, should address:
Related PRs
Resume().Changes
Changes to
dbus_service/dbus-serviceandvaliditysensor/usb.py:init.open()instead ofinit.open_common()to get a fresh USB handleopen_dev()to raiseUSBErrorinstead of a bareExceptionwhen the device is not found, so the retry loop can catchUSBErrorspecificallyTesting
Tested on a ThinkPad X1 Carbon 6th Gen (
06cb:009aSynaptics reader) running Arch Linux (Omarchy) withopen-fprintd+python-validity. Multiple suspend/resume cycles — USB device typically enumerates after 0-2 failed attempts (~0-200ms). Fingerprint verification works reliably after wake. Tested both successful matches and no-match retries across multiple cycles without service crashes.